﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MAT.Model;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Windows.Forms;
namespace MAT.Controllers
{
    class ctrReportRoom
    {
        private frmReportRoom _frmReportRoom = null;

        public frmReportRoom FrmReportRoom
        {
            get { return _frmReportRoom; }
            set { _frmReportRoom = value; }
        }

        MAT_Context context = MATContext.getContext();
        CommonClass ccl = new CommonClass();

        private bool check(TextBox tb)
        {
            foreach (ROOM room in context.ROOMs.ToList())
            {
                if (tb.Text == room.ROOM_NAME)
                    return true;
            }
            MessageBox.Show("ROOM is wrong!");
            tb.Text = "";
            tb.Focus();
            return false;
        }

        public void btnReportRoom_Click()
        {
            if (check(_frmReportRoom.textBox1))
            {
                ReportDocument cryRpt = new ReportDocument();
                cryRpt.Load(Application.StartupPath + @"\..\..\Reports\crpReportRoom.rpt");

                ccl.automationConnect(cryRpt);
                ccl.report_Parameter(cryRpt, _frmReportRoom.textBox1.Text, "RoomName");

                _frmReportRoom.crystalReportViewer1.ReportSource = cryRpt;
                _frmReportRoom.crystalReportViewer1.Refresh();
            }
        }

        public void button1_Click()
        {
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(Application.StartupPath + @"\..\..\Reports\crpReportAllRoom.rpt");
            ccl.automationConnect(cryRpt);
            _frmReportRoom.crystalReportViewer1.ReportSource = cryRpt;
            _frmReportRoom.crystalReportViewer1.Refresh();
        }

        public void btnExport_Click()
        {
            _frmReportRoom.crystalReportViewer1.ExportReport();
        }

        public void btnPrint_Click()
        {
            _frmReportRoom.crystalReportViewer1.PrintReport();
        }
    }
  
}
